function stz =mkswtable(x,ndpris);
%MKSWTABLE: generates a string that can be used to create a table in scientific workplace.
%by Rob Vigfusson 10 October 1999
%Instructions: You want to copy a matrix X from Matlab into Scientfic Workplace.
%Run this command with X as the only argument. 
%Copy the resulting output string 
% In SW select paste special. Select the internal button. 
% This results in a table that you can edit in scientific workplace. 
% The second argument controls the formatting. 
% It works like the num2str command. 
% mkswtable(X,N) converts the matrix X into a string representation
% with a maximum N digits of precision.  The default number of digits is
% based on the magnitude of the elements of X.
% mkswtable(X,FORMAT) uses the format string FORMAT (see SPRINTF for details). 

[nrows,ncols]= size(x);

%This code tells SW that you are making a table.
stz = ['\TABLE{' num2str(ncols) ',' num2str(nrows) '}{c}\VR'];

%The following lines are formatting instructions. 
for zq = 1:ncols;
   stz =[stz '{,,c,,,}'];
end;

stz =[stz '{,,,,,}\HR{'];

for zy = 1:nrows;
   stz = [stz ','];
end;

stz = [stz '}'];
x=x';


%now I enter the contents of the matrix into the table. 
if nargin == 1;
   for zx=1:nrows*ncols;
      stz = [stz '\CELL{' num2str(x(zx)) '}'];
   end;
else;
    for zx=1:nrows*ncols;
      stz = [stz '\CELL{' num2str(x(zx),ndpris) '}'];
   end;

end;

